/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package systole.processor.filters;

/**
 *
 * @author user
 */
public class LowPass extends Filter implements Cloneable{
	
    
    /**
     * @param Ps
     * @param fc
     */
    public LowPass(double Ps, double fc){
        super(Ps);
        this.cutOffFrequency = fc;
    }

    
    @Override
	public FilterConfiguration config(int order, double atten, double ripple, double trband){
        
        int numBands = 2;
        double deltaP = 0.5f*(1.0f - (float)Math.pow(10.0f, -0.05f*ripple));
        double deltaS = (float)Math.pow(10.0f, -0.05f*atten);
        double rippleRatio = deltaP / deltaS;

        double[] bands = new double[2*numBands];
        double[] desired = new double[numBands];
        double[] weights = new double[numBands];

        double fcNorm = normalizeFreq(this.cutOffFrequency)/this.getSamplingFrequency();

        desired[0] = 1.0;
        desired[1] = 0.0;

        bands[0] = 0.0;
        bands[1] = fcNorm;
        bands[2] = fcNorm + trband;
        bands[3] = 0.5;

        weights[0] = 1.0;
        weights[1] = rippleRatio;


        FilterConfiguration filtConfig = new FilterConfiguration();
        filtConfig.setOrder(order);
        filtConfig.setAtten(atten);
        filtConfig.setRipple(ripple);
        filtConfig.setTrband(trband);
        filtConfig.setBands(bands);
        filtConfig.setDesired(desired);
        filtConfig.setWeights(weights);

        return filtConfig;
        

    }


    @Override
    public Object clone(){
        LowPass lp = null;

        try{
            lp = (LowPass)super.clone();
            lp.setSamplingPeriod(this.ps);
            lp.coeffs = this.coeffs;
            lp.cutOffFrequency = this.cutOffFrequency;
        }catch(CloneNotSupportedException ex){
            ex.printStackTrace();
        }

        return lp;
    }

}
